﻿using System.Collections;
using System.Collections.Generic;
using System;
using System.Text;
using System.IO;
using System.Data;
using System.Xml;
using System.Web.Security;
using System.Security.Cryptography;
using System.Net;
using System.Web;

using com.paypal.sdk.util;

namespace Gift.WebApp
{

    /// <summary>
    ///Util 的摘要说明
    /// </summary>
    public class Util
    {
      static  int num6 = 0;
        // Methods
        public static string BuildResponse(object response, string header1, string header2)
        {
            if (response != null)
            {
                NVPCodec codec = new NVPCodec();
                codec = (NVPCodec)response;
                string str = "<center>";
                if (header1 != null)
                {
                    str = str + "<font size=2 color=black face=Verdana><b>" + header1 + "</b></font>";
                }
                str = str + "<br>" + "<br>";
                if (header2 != null)
                {
                    str = str + "<b>" + header2 + "</b><br>";
                }
                str = str + "<br>" + "<table width=400 class=api>";
                for (int i = 0; i < codec.Keys.Count; i++)
                {
                    str = ((str + "<tr><td class=field> " + codec.Keys[i].ToString() + ":</td>") + "<td>" + codec.GetValues(i)[0] + "</td>") + "</tr>" + "<tr>";
                }
                return (str + "</table>" + "</center>");
            }
            return "Requested action not allowed";
        }

        public static string GenerateCreditCardNumber(string cardType)
        {
            int[] numArray = new int[0x10];
            int num = 0x10;
            int num2 = 0;
            Random random = new Random();
            string str3 = cardType;
            if (str3 != null)
            {
                if (!(str3 == "Visa"))
                {
                    if (str3 == "Discover")
                    {
                        numArray[num2++] = 6;
                        numArray[num2++] = 0;
                        numArray[num2++] = 1;
                        numArray[num2++] = 1;
                    }
                    else if (str3 == "MasterCard")
                    {
                        numArray[num2++] = 5;
                        numArray[num2++] = ((int)Math.Floor((double)(random.NextDouble() * 5.0))) + 1;
                    }
                    else if (str3 == "Amex")
                    {
                        numArray = new int[15];
                        numArray[num2++] = 3;
                        numArray[num2++] = (random.Next(2) == 1) ? 7 : 4;
                        num = 15;
                    }
                }
                else
                {
                    numArray[num2++] = 4;
                }
            }
            for (int i = num2; i < (num - 1); i++)
            {
                numArray[i] = (int)Math.Floor((double)(random.NextDouble() * 10.0));
            }
            int num4 = 0;
            for (int j = 0; j < (num - 1); j++)
            {
                num6 = numArray[j];
                if ((j & 1) == (num & 1))
                {
                    num6 *= 2;
                }
                if (num6 > 9)
                {
                    num6 -= 9;
                }
                num4 += num6;
            }
            int[] numArray2 = new int[] { 0, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
            numArray[num - 1] = numArray2[num4 % 10];
            string str = string.Empty;
            foreach (int num6 in numArray)
            {
                str = str + num6;
            }
            return str;
        }

    }
}